package com.shiguiwu.springmybatis.designpattern.decorator;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @description: 继承的方法实现，不科学的方法
 * @author: stone
 * @date: Created by 2021/8/27 10:05
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.designpattern.decorator
 */
public class LoginSsoHandler extends SsoInterceptor {

    private static Map<String, String> authMap = new ConcurrentHashMap<>();

    static {
        authMap.put("huahua", "queryUserInfo");
        authMap.put("doudou", "queryUserInfo");
    }

    @Override
    public boolean preHandle(String request, String response, Object handler) {
        //模拟获取票据
        String ticket = request.substring(1, 8);
        //模拟校验
        boolean success = "success".equals(ticket);

        if (!success) {
            return false;
        }

        String userId = request.substring(9);
        String method = authMap.get(userId);

        //校验是否有权限访问方法
        return "queryUserInfo".equals(method);
    }

}
